package com.dao.order;

import javax.annotation.Resource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.query.Query;
import org.springframework.stereotype.Repository;

import com.entity.Order;
import com.entity.Pets;

@Repository
public class OrderDaoImpl implements OrderDao{
	@Resource
	private SessionFactory sessionFactory;
	private Session getSession(){
		return sessionFactory.getCurrentSession();
	}

	@Override
	public boolean savaOrder(OrderDao order) {
		return (boolean) getSession().save(order);
	}

	@Override
	public boolean deleteOrder(int id) {
		Transaction tran=getSession().beginTransaction();
		String hql="delete from order where id=?";
		Query<?> q=getSession().createQuery(hql);
		q.setParameter(0,id);
		q.executeUpdate();
		tran.commit();
		return true;
	}

	@Override
	public Order selectOrder(int id) {
		String hql = "select * from order where id=?";
		Query<?> query=getSession().createQuery(hql);
		query.setParameter(0,id);
		Order order=(Order) query.uniqueResult();
		return order;
	}
	

}
